/*
 * ===================================================================
 *  
 *      Filename: log_client_api.h
 *
 *   Description: this is the public interface for the hplog client
 *
 *       Version:  1.0
 *        Create:  2010/07/13
 *
 *        Author:  Keven Zhu     kevenzhu@tencent.com
 *     Copyright:  Reserved by Tencent.com Co.ltd
 *          
 * ====================================================================
 */
#ifndef __LOG_CLIENT_APIT__
#define __LOG_CLIENT_APIT__
#include <linux/types.h>

#define MAX_LOG_PATH_SIZE     256
#define MAX_PROCESS_NAME_SIZE 16
#define MAX_LOG_SIZE          (1*1024*1024*1024)   /*Default value:Max 1G local log files*/

enum log_level
{
    DEBG = 0,       /* debug-level messages              */
    INFO = 1,       /* informational                    */
    NOTC = 2,       /* normal but significant condition  */
    WARN = 3,       /* warning conditions                */
    EROR = 4,       /* error conditions                  */
    CRIT = 5,       /* critical conditions               */
    ALET = 6,       /* action must be taken immediately  */
    EMGT = 7,       /* system is unusable                */
    LEVEL_MAX = EMGT
};

/*the "init_hplog" must be called firstly, then call the following ones*/
/* Notice:
 * 1.The '\n' will be added at the end of the line
 * 2.The following contents are added to the head,The format of 
 *   the additional msg likes this
 * |-------------------------------------------------------------
 * |   date  |  severity | process name(opt) |  seq |  pid      |
 * --------------------------------------------------------------
 *  date:    timestamp of the PC,format 2010/06/13 19:52:37
 *  severity:log level
 *  pname:   process name which is assigned by you(optional)
 *  seq:     sequence of the packet, increase each packet
 *  pid:     process ID of the client*/
#define tx_log(level,fmt,args...) hplog_output(level,fmt,##args)
#define log_emgt(fmt,args...) hplog_output(EMGT,fmt,##args)
#define log_alet(fmt,args...) hplog_output(ALET,fmt,##args)
#define log_crit(fmt,args...) hplog_output(CRIT,fmt,##args)
#define log_eror(fmt,args...) hplog_output(EROR,fmt,##args)
#define log_warn(fmt,args...) hplog_output(WARN,fmt,##args)
#define log_notc(fmt,args...) hplog_output(NOTC,fmt,##args)
#define log_info(fmt,args...) hplog_output(INFO,fmt,##args)
#define log_debg(fmt,args...) hplog_output(DEBG,fmt,##args)

enum protocol
{
    LOG_TCP = 1,        /*send the packet to the server with TCP protocol*/
    LOG_UDP = 2,        /*send the packet to the server with UDP protocol*/
    LOG_MAX = LOG_UDP
};

/*defination for the flags*/
#define LOG_MSG_STORE_LOCAL   0x01
#define LOG_MSG_STORE_REMOTE  0x02
#define LOG_MSG_STORE_MONITOR 0x04

typedef struct log_client_conf_
{
    /*the path of the local log file,the path MUST exist!!!*/
    char     local_log_path[MAX_LOG_PATH_SIZE];
    /*the name of the process,pass the address of argv[0] to the process_name*/
    char     process_name[MAX_PROCESS_NAME_SIZE];
    /*if the log_level greater or equal than serverity,we will process it,otherwise ignored*/
    unsigned char log_severity;
    /*NOT used, but if the log_level is greater than WARN,the log will be sent with TCP, defualt UDP*/
    unsigned char protocol;
    /*reserved for the future use*/
    unsigned char reserved;
    /*the max log size,if exceed,rotate to the begin,the number is defined as byte*/
    uint     max_log_size; 
    /*flags to control the action of the log*/
    uint     flags;
}log_client_conf;

#ifdef __cplusplus
extern "C" {
#endif
/* initialize the log modules
 * @log_conf: the configuration for the log, please make sure the unset fields are placed with zero
 *  
 * return value:
 * positive means failure,error could be found in the head file or with the help of log_error();
 * 0 means ok*/
extern int init_hplog(log_client_conf *log_conf);

/* set client log control level in the running time
 * @log_level: the log level for this client,the range of the log level is 0-8, 8 means that all
 *             the log msgs are forbidden
 *
 * return value:
 * positive means failure,error could be found in the head file or with the help of log_error();
 * 0 means ok*/
extern inline int set_client_log_level(int log_level);

/* format the error msg according to the error number*/
extern char* plogerr(int errno);

/*main interface for the log output*/
extern int hplog_output(int log_level,const char*fmt,...);
#ifdef __cplusplus
}
#endif

/*define the numeric error code*/
#define NOERR     0
#define NOMEM     1
#define INVIO     2
#define NOSPC     3
#define NOSRV     4
#define NOPMT     5
#define SKTMO     6
#define RSTBP     7
#define REJBP     8
#define NOCNF     9
#define FOPFI     10
#define FLKFI     11
#define FGTHL     12
#define FLDON     13
#define FITSM     14
#define FMPMM     15
#define FSTSM     16
#define ERRMP     17
#define FQFUL     18
#define FDNRG     19
#define NITCL     20
#define FLOG      21
#define FUDPY     22

#endif


